package com.taldh.mutlithread;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class WaitNotifyThreadTest {

    public static void main(String[] args) {
        Object lock = new Object();
        new ThreadC(lock).start();
        new ThreadA(lock).start();
        new ThreadB(lock).start();

    }

    public static class UserLogInfo{
        public void statistics(List<LogSub> logs){
            if(CollectionUtils.isEmpty(logs)) {
                return;
            }

            //1. 统计
            //2. 排序
            //3. 显示
            List<LogSub> logsFilter = logs.parallelStream()
                    .filter(log -> log.loginTimestamp.compareTo(DateUtils.addDays(new Date(), -10)) > 0).collect(Collectors.toList());
            Map<String, LogSub> collect = logsFilter.parallelStream().collect(Collectors.toMap(Log::getClientId, LogSub::incre));

        }
    }

    class LogSub extends Log {
        int count;

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }

        public LogSub incre() {
            count ++;
            return this;
        }
    }

    class Log {
        String clientId;
        String userName;
        Date loginTimestamp;

        public String getClientId() {
            return clientId;
        }

        public void setClientId(String clientId) {
            this.clientId = clientId;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public Date getLoginTimestamp() {
            return loginTimestamp;
        }

        public void setLoginTimestamp(Date loginTimestamp) {
            this.loginTimestamp = loginTimestamp;
        }
    }
}
